package chapter2.No2_3_volatile关键字.gSynchronized代码块有volatile同步的功能;

/**
 * Created by Administrator on 2016/11/16.
 */
public class ServiceClass {

    private boolean flag = true;

    public void methodA() {
        while (flag) {
            try {
                Thread.sleep(500);
                System.out.println(Thread.currentThread().getName() + " 线程执行中！");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(Thread.currentThread().getName() + "停止下来");
    }

    public void stop() {
        flag = false;
        System.out.println("现在立即停止");
    }


}
